package sk.xorty.quartz;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Listens to execution of PrimeNumbersJob
 */
public class PrimeJobsListener implements JobListener {

    protected final String jobName = "primeJobsListener";
    protected AtomicInteger count = new AtomicInteger();

    @Override
    public String getName() {
        return jobName;
    }

    @Override
    public void jobToBeExecuted(JobExecutionContext context) {
        // do nothing
    }

    @Override
    public void jobExecutionVetoed(JobExecutionContext context) {
        // do nothing
    }

    @Override
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
        System.out.println("Listening to job execution ...");
        count.incrementAndGet();
    }

    public AtomicInteger getCount() {
        return count;
    }
}
